#include <STC89C5xRC.H>
#include "Timer0.h"
#include "Delay.h"
#include "Nixie.h"
#include "Key.h"

sbit LED = P2^0;
sbit Motor = P1^0;

unsigned char Counter,Compare;
unsigned char KeyNum,Speed;

void main()
{	
	Timer0Init();
	while(1)
	{
		KeyNum=Key();
		if(KeyNum==1)
		{
			Speed++;
			Speed%=4;
			if(Speed==0){Compare=0;}
			if(Speed==1){Compare=50;}
			if(Speed==2){Compare=75;}
			if(Speed==3){Compare=100;}
		}
		NiXie_SetBuf(1,Speed);
	}
}

void Timer0_Routine() interrupt 1
{	
	TL0 = 0xA4;	
	TH0 = 0xFF;
	Key_Loop();
	NiXie_Loop();
	Counter++;
	Counter %= 100;//Counter到100就重置为0
	if(Counter<Compare)
		Motor=1;
	else
		Motor=0;
}